<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title>Web Workers via Gears Test</title>
	<script type="text/javascript" src="/svn/trunk/src/gears_init.js"></script>
	<script type="text/javascript" src="/svn/trunk/test/jsunity/jsunity.js"></script>
	<script type="text/javascript">
		
		window["html5-shim.baseURL"] = "/svn/trunk/src/";
		
		function runTest (testName,func) {
			testName = testName.indexOf("test")===0 ? testName : "test" + testName;
			var tst = {};
			tst[testName]=func;
			return jsUnity.run(tst);
		}
		jsUnity.log = function (msg) {
			document.getElementById("demoworkers").innerHTML+=msg + "\n";
		};
	</script>
</head>

<body>
	<h1>Web Workers API Shim Core &amp; Child Workers Test Suite</h1>
		
	<textarea rows="8" cols="100" id="demoworkers"></textarea>
	
	<h3>A Peek at the Worker's Internal Code</h3>
	<textarea rows="30" cols="100" id="workercode"></textarea>
		
	<script type="text/javascript" src="/svn/trunk/src/DedicatedWorker.js"></script>
	<script type="text/javascript">
			runTest("InitWorkerUndefined",function() { jsUnity.assertions.assertEqual(typeof(InitWorker),"undefined","init worker is undefined"); });
			var w = new Worker("workers/child.js");

			// take a peek at the inner workings, if a shimmed worker
			if (w._source) { document.getElementById("workercode").innerHTML = w._source; }

			w.onmessage = function(event) {
				document.getElementById("demoworkers").innerHTML+=event.data + "\n";
				
				// for all tests, echo back
				if (event.data.indexOf && event.data.indexOf("testing") != -1) { w.postMessage(event.data.replace("testing","tested")); }
			};
			// start the tests, providing the role to the first child worker
			w.postMessage("worker");
			w.postMessage("another message from parent");
	</script>
</body>
</html>